import { errFeedBack, completeInfo } from '../../utils/api.js';
var app = getApp();
Component({

    behaviors: [],

    properties: {
        ModalStatus: Boolean,
        btnStatus: Boolean,
        textareaStatus: Boolean,
        flag: Boolean,
        height: String
    },
    data: {
        btnInfo: [{
            id: 1,
            url: '/image/wrong.png',
            title: '题目或答案错误'
        }, {
            id: 2,
            url: '/image/detail.png',
            title: '答案不够详细'
        }, {
            id: 3,
            url: '/image/understand.png ',
            title: '图片太模糊'
        }, {
            id: 4,
            url: '/image/other.png ',
            title: '其他'
        }],
    }, // 私有数据，可用于模版渲染

    // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
    created: function () { },
    attached: function () {

    },
    moved: function () { },
    detached: function () { },

    methods: {
        util: function (e) {
            if (e.detail) {
                new Promise((resolve, reject) => {
                    if (app.globalData.university || app.globalData.phone) {
                        completeInfo(app.globalData.university, app.globalData.phone, () => {
                            resolve();
                        })
                    }
                }).then(() => {
                    errFeedBack(this.id, this.data.content, () => {
                        this.setData({
                            content: ''
                        })
                    })
                })
            }
        },
        hiddendAll: function () {
            this.setData({
                ModalStatus: false,
                btnStatus: false,
            })
        },
        submit: function (e) {
            var content = e.detail.value.content;
            if (app.globalData.university && app.globalData.phone) {
                this.setData({
                    content: ''
                })
            } else {
                this.setData({
                    content: content
                })
            }
            this.ImproveInfo(this.id, content);
        },
        ImproveInfo: function (id, content) {
            var phone = app.globalData.phone;
            var university = app.globalData.university;
            if (content) {
                if (phone && university) {
                    var promise = new Promise((resolve, reject) => {
                        wx.showToast({
                            title: '反馈成功',
                            icon: 'success',
                            success: function () {
                                setTimeout(resolve, 1500)
                            }
                        })
                    })
                    promise.then(() => {
                        errFeedBack(this.id, content)
                    })
                } else if (!phone && university) {
                    var promise = new Promise((resolve, reject) => {
                        wx.showToast({
                            title: '请补全手机号',
                            icon: 'none',
                            duration: 1500,
                            success: function () {
                                setTimeout(resolve, 1500)
                            }
                        })
                    })
                    promise.then(() => {
                        this.setData({
                            show: true,
                            arr: [{
                                id: 2,
                                name: 'phoneNum',
                                placeholder: '请输入您手机号'
                            }]
                        })
                    })
                } else if (phone && !university) {
                    var promise = new Promise((resolve, reject) => {
                        wx.showToast({
                            title: '请补全大学信息',
                            icon: 'none',
                            duration: 1500,
                            success: function () {
                                setTimeout(resolve, 1500)
                            }
                        })
                    })
                    promise.then(() => {
                        this.setData({
                            show: true,
                            arr: [{
                                id: 1,
                                name: 'university',
                                placeholder: '请输入您所在大学'
                            }]
                        })
                    })

                } else {
                    var promise = new Promise((resolve, reject) => {
                        wx.showToast({
                            title: '请补全个人信息',
                            icon: 'none',
                            duration: 1500,
                            success: function () {
                                setTimeout(resolve, 1500)
                            }
                        })
                    })
                    promise.then(() => {
                        this.setData({
                            show: true,
                            arr: [{
                                id: 1,
                                name: 'university',
                                placeholder: '请输入您所在大学'
                            },
                            {
                                id: 2,
                                name: 'phoneNum',
                                placeholder: '请输入您手机号'
                            }
                            ]
                        })
                    })
                }
                this.setData({
                    ModalStatus: false,
                    btnStatus: false,
                    textareaStatus: false,
                    flag: false,
                })
            } else {
                wx.showToast({
                    title: '内容不能为空',
                    icon: 'none',
                    duration: 1500
                })
            }
        },
        powerDrawer: function (e) {
            var index = e.currentTarget.dataset.index;
            var value = e.currentTarget.dataset.title;
            if (index == 4) {
                this.setData({
                    textareaStatus: false,
                    btnStatus: false,
                    height: '600rpx',
                    top: '43%',
                    marginTop: '55px',
                })
            } else {
                this.setData({
                    content: '',
                    textareaStatus: true,
                    ModalStatus: false,
                    content: value
                })
                this.ImproveInfo(this.id, value)
            }
        },
    }
})